package com.china08.yxyapi.api.manage.tec.teaching.weikecheng.upload;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.res.YxyResVideoBlock;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyResVideoBlockRepository;

/**
 * 根据md5和片段 查看是否已经上传过
 * 
 * @author Json
 *
 */
@CrossOrigin
@RestController
public class WeikechengCheckBlockController extends YxyApiBaseController {

    @Autowired
    private YxyResVideoBlockRepository yxyResVideoBlockRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/weikecheng/check/block", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(@RequestBody ReqModel model) {
        RespModel respModel = new RespModel();
        YxyResVideoBlock videoBlock = yxyResVideoBlockRepository.findByMd5AndChunk(model.md5, model.chunk);
        // 片段已存在
        if (videoBlock != null) {
            respModel.status = 1;
        }
        return respModel;
    }

    protected static class RespModel extends YxyApiRespModel {
        public Integer status = 0;
    }

    protected static class ReqModel extends YxyApiReqModel {

        public String md5;// 整个文件的md5
        public Integer chunk;// 当前第几片
    }

}